<?php
$this->pageTitle = 'Pridať ponuku/dopyt';
?>

<div class="newForm">
	<h3>Pridať ponuku/dopyt</h3>
	<?php echo $this->Form->create('Market'); ?>
		<fieldset>
		<?php
			echo $this->Form->input('description', array('label' => 'Popis'));

			$options = array(
				0 => 'vyberte typ',
				1 => 'dopyt',
				2 => 'ponuka'
			);
			$params = array('label' => 'Typ', 'options' => $options);
			if (isset($canShowCommission) && $canShowCommission === TRUE) {
				$params['onchange'] = 'displayCommission();';
			}
			echo $this->Form->input('type', $params);
			
			if ($loggedUserIsAdmin === TRUE) {
				echo $this->Form->input('fk_client_id', array('label' => 'Klient', 'options' => $clientList, 'div' => array('id' => 'ExistingClientDiv', 'style' => (isset($this->request->data['Market']) && $this->request->data['Market']['client_check'] == 1) ? 'display:none;' : '')));
				echo '<a id="NewClientLink" href="#" onclick="displayClientDiv(1); return false;" style="' . (isset($this->request->data['Market']) && $this->request->data['Market']['client_check'] == 1 ? 'display:none;' : '') . '";>Nový klient</a>';
				echo '<a id="ExistingClientLink" href="#" onclick="displayClientDiv(2); return false;" style="' . (isset($this->request->data['Market']) && $this->request->data['Market']['client_check'] == 1 ? '' : 'display:none;') . '">Existujúci klient</a>';
			}

			echo '<div id="NewClientDiv" style="' . ($loggedUserIsAdmin === TRUE ? (isset($this->request->data['Market']) && $this->request->data['Market']['client_check'] == 1 ? '' : 'display:none;') : '') . '">';
			echo $this->Form->input('Person.name', array('label' => 'Meno'));
			echo $this->Form->input('Person.surname', array('label' => 'Priezvisko'));
			echo $this->Form->input('Person.email', array('label' => 'E-mail'));
			echo $this->Form->input('Person.phone', array('label' => 'Telefónne číslo'));
			echo '</div>';
			echo $this->Form->hidden('client_check', array('value' => $loggedUserIsAdmin === TRUE ? 0 : 1));
			if ($loggedUserIsAdmin === TRUE) {
				echo $this->Form->input('fk_tipster_id', array('label' => 'Tiper', 'options' => $tipsterList));
				echo $this->Form->input('fk_broker_id', array('label' => 'Maklér', 'options' => $brokerList));
			}
			echo $this->Form->input('commission', array('label' => 'Provízia', 'value' => 0, 'div' => array('id' => 'CommissionDiv', 'style' => 'display:none;')));
		?>
		</fieldset>
	<?php echo $this->Form->end(__('Uložiť')); ?>
</div>